package com.xm_jd.controller.jiesuan;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.BalanceDao;
import com.xm_jd.model.entitys.Balance;
import com.xm_jd.model.entitys.tb_car;
import com.xm_jd.model.entitys.tb_dd;
import com.xm_jd.model.entitys.user;
import com.xm_jd.utils.BaseServlet;

/**���ɽ��˵���ϸ��Ϣ
 * Servlet implementation class JieXiangServlet
 */
@WebServlet("/moeny")
public class JieXiangServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public JieXiangServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				request.setCharacterEncoding("utf-8");
				//request.getSession().getAttribute("");
				//��ҳ���ȡ��Ʒ���
				String abb = request.getParameter("abb");
				String[] shoopid = abb.split(",");
				String dizi=request.getParameter("shid");
				List<Balance> list = new ArrayList<>();
				user aa=(user) request.getSession().getAttribute("users");
				//ͳ�ƶ����ܶ�
				String jinge=request.getParameter("jinge");
				BigDecimal jine = BigDecimal.valueOf(Double.parseDouble(jinge));
				request.getSession().setAttribute("jinge", jinge);
				//���ɶ�����(�ҵı����Զ�����)	
				int suiji=(int)(100000000+Math.random()*(999999999-100000000-1));
				request.getSession().setAttribute("suiji", suiji);
				//���붩����Ϣ
				int result = new BalanceDao().adddingdan(new tb_dd(suiji,new java.sql.Timestamp(new Date().getTime()),aa.getUser_id(),jine,jine,"待付款",Integer.parseInt(dizi)));
					//�Ȳ����굥��Ϣ
					for(int i=0;i<shoopid.length;i++){
						tb_car car = new BalanceDao().getcarnum(aa.getUser_id(),Integer.parseInt(shoopid[i]));
						new BalanceDao().addxiangdan(suiji, car.getCar_shoop_sid(), car.getCar_gounum());
						//ɾ�����ﳵ�ж�Ӧ����Ʒ
						new BalanceDao().deletecar(car.getCar_id());
					}
				//ת��ҳ��
				/*request.getRequestDispatcher("jsps/Moeny.jsp").forward(request, response);*/
				//response.sendRedirect("jsps/Moeny.jsp");
				this.forward("Moeny");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
